package com.yonyou.pmclouds.discuss.impl;

import com.yonyou.pmclouds.basecom.exception.BusinessException;
import com.yonyou.pmclouds.discuss.entity.DiscussionVO;
import com.yonyou.pmclouds.discuss.itf.AbstractSpecifiedTypeDiscussProcessor;
import com.yonyou.pmclouds.siteinspection.entity.SiteInspectionVO;
import com.yonyou.pmclouds.siteinspection.rmiitf.SiteInspectionQuery;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.HashMap;
import java.util.Map;

public class InspectionDiscussProcessor extends AbstractSpecifiedTypeDiscussProcessor {
    @Autowired
    private SiteInspectionQuery query;

    @Override
    protected Map<String, String> getUserTitle(DiscussionVO discussion) throws BusinessException {
        SiteInspectionVO siteInspection = query.queryOne(discussion.getRelateKey());
        Map<String, String> result = new HashMap<>(1);
        // get @ users
        String[] atUsers = extractMentionedUser(discussion.getContent());
        String atMessage = discussion.getCreatorName() + getMessageAt();
        for (String atUser : atUsers) {
            result.put(atUser, atMessage);
        }
        int type = getDiscussType(discussion);
        String msgHead = discussion.getCreatorName() + getDiscussTypeMessage(type);
        if (type == REPLY_TYPE) {
            // 回复，需要被回复人和评论人消息
            if (!StringUtils.isEmpty(discussion.getRepliedUser())) {
                result.put(discussion.getRepliedUser(),
                        msgHead + getMessageReply());
            }
            DiscussionVO repliedDiscuss = getRepliedDiscuss(discussion);
            if (repliedDiscuss != null) {
                result.put(repliedDiscuss.getCreator(),
                        msgHead + getMessageComment());
            }
        }
        result.put(siteInspection.getCreator(), msgHead + getMessageCreator());
        return result;
    }

    protected String getMessageAt() {
        return "";
    }

    protected String getMessageReply() {
        return "";
    }

    protected String getMessageComment() {
        return "";
    }

    protected String getMessageCreator() {
        return "";
    }

    @Override
    public String getRelateType() {
        return "";
    }
}
